import React from 'react';
import { inject, observer } from 'mobx-react';
import { Button, Row, Col, Modal } from 'antd';
import { WeaDialog, WeaSearchGroup, WeaFormItem, WeaInput, WeaBrowser, WeaSelect, WeaLocaleProvider } from 'ecCom';
import { toJS } from 'mobx';
import equal from 'deep-equal';

const getLabel = WeaLocaleProvider.getLabel;

@observer
class HighSeasDispenseDialog extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      replaceDatas: [],
      ids: '',
    };
  }
  componentWillReceiveProps(nextProps) {

  }
  shouldComponentUpdate() {
    return true;
  }
  render() {
    const { showCustomerModal, showModal, CrmName } = this.props.contentStore;
    const formItemLayout = {
      labelCol: { span: 6 },
      wrapperCol: { span: 14 },
    };
    const { replaceDatas } = this.state;
    return (
      <WeaDialog
        ecId={`${this && this.props && this.props.ecId || ''}_WeaDialog@7ylt6y`}
        title={getLabel(126086, '分配客户经理')}
        icon="icon-coms-crm"
        iconBgcolor="#96358a"
        visible={showModal}
        style={{ width: 520, height: 200 }}
        buttons={[
          <Button ecId={`${this && this.props && this.props.ecId || ''}_Button@dy070l@save`} type="primary" onClick={() => this.doSave()} >{getLabel(86, '保存')}</Button>,
          <Button ecId={`${this && this.props && this.props.ecId || ''}_Button@vabjqm@close`} onClick={() => showCustomerModal(false)}>{getLabel(309, '关闭')}</Button>,
        ]}
        onCancel={() => showCustomerModal(false)}
        hasScroll
      >
        <WeaSearchGroup ecId={`${this && this.props && this.props.ecId || ''}_WeaSearchGroup@vedqsl`} needTigger title={getLabel(1361, '基本信息')} showGroup >
          <div>
            <WeaFormItem
              ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@k223qy`}
              label={getLabel(1268, '客户名称')}
              {...formItemLayout}
            >
              <WeaInput ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@t8dinu`} viewAttr={1} value={CrmName} />
            </WeaFormItem>
            <WeaFormItem
              ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@dg6p4j`}
              label={getLabel(1278, '客户经理')}
              {...formItemLayout}
            >
              <WeaBrowser ecId={`${this && this.props && this.props.ecId || ''}_WeaBrowser@qkm64u`} replaceDatas={replaceDatas} type={1} viewAttr={3} title={getLabel(1867, '人员')} onChange={(ids, names, datas) => { this.browserChange(ids, names, datas); }} />
            </WeaFormItem>
          </div>
        </WeaSearchGroup>
      </WeaDialog>
    );
  }

        browserChange =(ids, names, datas) => {
          this.setState({
            replaceDatas: datas,
            ids,
          });
        }

        doSave=() => {
          const { customerIds, saveCustomer, showCustomerModal } = this.props.contentStore;
          const { ids } = this.state;
          if (ids) {
            saveCustomer({ seasCustomerIds: customerIds, managerId: ids });
            // showCustomerModal(false);  //关闭
            this.setState({
              replaceDatas: [],
              ids: '',
            });
          } else {
            Modal.warning({
              title: getLabel(15172, '系统提示'),
              content: getLabel(129512, '必填字段不能为空！'),
              okText: getLabel(33703, '确定'),
            });
          }
        }
}

export default HighSeasDispenseDialog;
